package com.tanxi521.tnlevel.utils;

import com.tanxi521.tnlevel.TnLevel;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;

import java.util.LinkedHashMap;
import java.util.Set;

/**
 * @Author: i-xiaotian
 * @Date: 2022/3/13 3:59
 * @EMAIL: 1254806967@qq.com
 */
public class ConfigReader {

    public static boolean getMysqlUse() {
        return getPlugin().getBoolean("mysql.use");
    }

    public static String getMysqlDriver() {
        return getPlugin().getString("mysql.driver");
    }

    public static String getMysqlUrl() {
        return getPlugin().getString("mysql.url");
    }

    public static String getMysqlPort() {
        return getPlugin().getString("mysql.port");
    }

    public static String getMysqlUser() {
        return getPlugin().getString("mysql.user");
    }

    public static String getMysqlPassword() {
        return getPlugin().getString("mysql.password");
    }

    public static String getMysqlDatabase() {
        return getPlugin().getString("mysql.database");
    }

    public static LinkedHashMap<Integer, Long> getLevels() {
        ConfigurationSection levelConfig =
                getPlugin().getConfigurationSection("levels");
        Set<String> levels = levelConfig.getKeys(false);
        LinkedHashMap<Integer, Long> levelMap = new LinkedHashMap<>();
        for (String level : levels) {
            Long exp = levelConfig.getLong(level);
            levelMap.put(Integer.parseInt(level), exp);
        }
        return levelMap;
    }

    public static String getLevelUpTitle() {
        return getPlugin().getString("title");
    }

    public static boolean getIsSendMessage() {
        return getPlugin().getBoolean("expmessage.enable");
    }

    public static String getExpMessage() {
        return getPlugin().getString("expmessage.message");
    }

    public static Integer getPerPageCount() {
        return getPlugin().getInt("perPageCount");
    }

    public static Integer getPoolSize() {
        return getPlugin().getInt("poolSize");
    }

    public static ChatMessageType getMsgType() {
        String string = getPlugin().getString("expmessage.type");
        if (string.equals("actionbar")) return ChatMessageType.ACTION_BAR;
        if (string.equals("msg")) return ChatMessageType.CHAT;
        return ChatMessageType.CHAT;
    }

    public static FileConfiguration getPlugin() {
        return TnLevel.getInstance().getConfig();
    }

}
